package com.bcu.calculus.controller;

import com.bcu.calculus.UseToken;
import com.bcu.calculus.config.GlobalConfig;
import com.bcu.calculus.entity.Message;
import com.bcu.calculus.entity.Slist;
import com.bcu.calculus.entity.Tlist;
import com.bcu.calculus.service.TlistService;
import com.bcu.calculus.utils.LoadUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;

@Api(tags = "15  第三路由模块")
@RestController
@RequestMapping("/api/Tlist")
public class TlistController {

    @Resource
    private TlistService tlistService;

    @Resource
    private GlobalConfig globalConfig;

    @ApiOperation(value = "上传管理端图片")
    @PostMapping(value = "/manageImages", headers = "content-type=multipart/form-data")
    //@UseToken(level = 0)
    public String getmanageImages(@RequestParam(value = "file") MultipartFile[] files, HttpServletRequest request) throws IOException {
        return globalConfig.hostUrl + "bcucalculusFile/image/tlist/manageimage/" + LoadUtil.upload(globalConfig.filePath+"image/tlist/manageimage/", files, request);

    }

    @ApiOperation(value = "上传h5图片")
    @PostMapping(value = "/hfImages", headers = "content-type=multipart/form-data")
    //@UseToken(level = 0)
    public String gethfImages(@RequestParam(value = "file") MultipartFile[] files, HttpServletRequest request) throws IOException {
        return globalConfig.hostUrl + "bcucalculusFile/image/tlist/hfiveimage/" + LoadUtil.upload(globalConfig.filePath+"image/tlist/hfiveimage/", files, request);
    }

    @ApiOperation(value = "添加三级路由")
    @PostMapping(value = "/add")
    public Message<?> addTlist(Tlist tlist){
        return tlistService.addTlist(tlist);
    }

    @ApiOperation(value = "根据主键删除三级路由")
    @DeleteMapping(value = "/del")
    public Message<?> delTlist(String tlistId){
        return tlistService.delTlist(tlistId);
    }

    @ApiOperation(value = "获取所有的三级路由")
    @GetMapping(value = "/getAll")
    public Message<List<Tlist>> findAll(){
        return tlistService.selectAllTlist();
    }

    @ApiOperation(value = "根据主键获取三级路由")
    @GetMapping(value = "/getOne")
    public Message<Tlist> findOne(String tlistId){
        return tlistService.selectOneTlistById(tlistId);
    }

    @ApiOperation(value = "更新三级路由")
    @PutMapping(value = "/update")
    public Message<?> updateslist(Tlist tlist){
        return tlistService.updateTlist(tlist);
    }

    @ApiOperation(value = "根据二级路由Id获取三级路由")
    @GetMapping(value = "根据二级路由id获取三级路由")
    public Message<List<Tlist>> getTlistBySlistId(String slistId){
        return tlistService.getTlistBySlistId(slistId);
    }

    @ApiOperation(value = "根据用户类型返回三级路由")
    @GetMapping(value = "getTlistByUserType")
    public Message<List<Tlist>> getTlistByUserType(String userType){
      return tlistService.getTlistByuserType(userType);
    }

}
